package com.weixing.mall.provider.controller.rpc;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Lists;
import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.base.enums.WhetherEnum;
import com.weixing.mall.provider.api.model.vo.dto.DepotRPcVo;
import com.weixing.mall.provider.model.domain.Depot;
import com.weixing.mall.provider.service.IDepotExtraService;
import com.weixing.mall.provider.service.IDepotService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("api/depotrpc")
public class DepotRpcController {
    @Autowired
    private IDepotService depotService;
    @Autowired
    private IDepotExtraService depotExtraService;

    @GetMapping("getBycode")
    public Result<DepotRPcVo> getByDepotCode(String code){
        DepotRPcVo vo=new DepotRPcVo();
        Depot depot=depotService.getOne(new QueryWrapper<Depot>().eq("depot_code",code).eq("is_enable", WhetherEnum.YES.getValue()));
        BeanUtils.copyProperties(depot,vo);
        return ResultUtil.success(vo);
    }
    @GetMapping("getDepotId")
    public Result<List<DepotRPcVo>> getByDepotCode(Long  getDepotId){
        List<DepotRPcVo> voList= Lists.newArrayList();
       List< Depot> depot=depotService.list(new QueryWrapper<Depot>().eq("dept_id",getDepotId).eq("is_enable", WhetherEnum.YES.getValue()));
       for(Depot tt:depot){
           DepotRPcVo vo=new DepotRPcVo();
           BeanUtils.copyProperties(tt,vo);
           voList.add(vo);
       }
        return ResultUtil.success(voList);
    }

    @GetMapping("delByCondition")
    public Result delByCondition(Long depotId,Long productId,String depotSn){
        depotExtraService.delByCondition(depotId, productId, depotSn);
        return ResultUtil.success();
    }

    @GetMapping("getById")
    public Result<DepotRPcVo> getById(Long  id){
        Depot depot = depotService.getById(id);
        DepotRPcVo vo=new DepotRPcVo();
        BeanUtils.copyProperties(depot,vo);
        return ResultUtil.success(vo);
    }
}
